import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';

export interface topicAttributes {
  id: number;
  name: string;
  count: number;
  browse: number;
  createdAt: Date;
  updatedAt: Date;
}

export type topicPk = "id";
export type topicId = topic[topicPk];
export type topicOptionalAttributes = "id" | "count" | "browse" | "createdAt" | "updatedAt";
export type topicCreationAttributes = Optional<topicAttributes, topicOptionalAttributes>;

export class topic extends Model<topicAttributes, topicCreationAttributes> implements topicAttributes {
  id!: number;
  name!: string;
  count!: number;
  browse!: number;
  createdAt!: Date;
  updatedAt!: Date;


  static initModel(sequelize: Sequelize.Sequelize): typeof topic {
    return topic.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "主键ID"
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "名称"
    },
    count: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: "个数"
    },
    browse: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "浏览数量"
    }
  }, {
    sequelize,
    tableName: 'topic',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
  }
}
